package com.example.demo.controller;

import com.example.demo.cons.DingdianCons;
import com.example.demo.domain.ContentDO;
import com.example.demo.domain.ResultVO;
import com.example.demo.service.AbstractDingdianService;
import com.example.demo.util.StringUtil;

public class DefalutDingdianController {

    private AbstractDingdianService service;

    public ResultVO getResultVO(String url, String dataType,Integer expect) {
        if (StringUtil.isEmpty(url)) {
            return ResultVO.error("url empty");
        }
        try {
            if (!Integer.valueOf(dataType).equals(expect)) {
                return ResultVO.error("dataType ERROR");
            }
        } catch (NumberFormatException e) {
            return ResultVO.error("dataType ERROR");
        }
        url = DingdianCons.DOMAIN + url;
        ContentDO contentDO = service.getContentDO(url);
        ResultVO success = ResultVO.success(contentDO);
        return success;
    }

    public void setService(AbstractDingdianService service) {
        this.service = service;
    }
}
